import Vue from "vue";
import Vuex from "vuex";
import VuexPersistedstate from "vuex-persistedstate";
import user from "@/store/modules/user";
import token from "@/store/modules/token";
import tab from "@/store/modules/tab";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    activeMenu: {},
  },
  getters: {},
  mutations: {
    setActiveMenu: (state, menu) => {
      state.activeMenu = menu;
    },
    removeActiveMenu: (state) => {
      state.activeMenu = {};
    },
  },
  actions: {},
  modules: {
    user,
    token,
    tab,
  },
  plugins: [
    VuexPersistedstate({
      storage: window.sessionStorage,
      reducer: (state) => ({
        token: state.token,
        activeMenu: state.activeMenu,
      }),
    }),
  ],
});
